#include "widget.h"
#include "ui_widget.h"
#include <QPixmap>
#include <QPainter>
#include <QImage>
#include <QPicture>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //painter.drawPixmap(xpos,0, QPixmap("D:/selfad/qt-opengl/images/awesomeface.png"));

    // 专门为平台做了优化
//    QPixmap pix(300,300);
//    // 填充颜色
//    pix.fill(Qt::white);

//    QPainter painter(&pix);
//    painter.setPen(QPen(Qt::green));
//    painter.drawEllipse(QPoint(150,150), 100,100);

//    pix.save("D:/pix.png");

    // QImage 绘图
//    QImage img(300, 300, QImage::Format_ARGB32);
//    img.fill(Qt::white);

//    QPainter painter(&img);
//    painter.setPen(QPen(Qt::blue));
//    painter.drawEllipse(QPoint(150,150), 100,100);

//    img.save("D:/img.png");

    // QPicture 绘图设备 可以记录和重新绘图指令

//    QPicture pic;
//    QPainter painter;
//    painter.begin(&pic);

//    painter.setPen(QPen(Qt::cyan));
//    painter.drawEllipse(QPoint(150,150), 100,100);

//    painter.end();

//    pic.save("D:/pic.zt");
}

void Widget::paintEvent(QPaintEvent *event)
{
    // 利用QImage, 对像素进行修改
//    QImage img;
//    img.load("D:/selfad/qt-opengl/images/awesomeface.png");

//    QPainter painter(this);

//    for(int i=50;i<100;++i){
//        for(int j=50;j<100;++j) {
//            QRgb value = qRgb(255,0,0);
//            img.setPixel(i,j,value);
//        }
//    }

//    painter.drawImage(0,0,img);


    // 重现QPicture
    QPicture pic;
    pic.load("D:/pic.zt");
       QPainter painter(this);
       painter.drawPicture(0,0,pic);
}
Widget::~Widget()
{
    delete ui;
}

